package core.evolutionary;

import java.util.HashSet;
import java.util.Set;


public class Island {
	private EvolutionaryEnvironment environment;
	private HashSet<Agent> agents;
	private boolean elitist;
	private double resources[];
	public Island baseIsland;
	
	
	public Island(EvolutionaryEnvironment environment, boolean elitist) {
		this.environment = environment;
		this.environment.add(this);
		this.elitist = elitist;
		this.resources = new double[1];
		this.agents = new HashSet<Agent>();
	}
	
	public Island(EvolutionaryEnvironment environment) {
		this(environment, false);
	}
	
	public boolean add(Agent e) {
		return agents.add(e);
	}
	

	public boolean remove(Agent e) {
		return agents.remove(e);
	}

	public Set<Edge> getMigratableEdges() {
		return getMigratableEdges(false);
	}
	
	public Set<Edge> getMigratableEdges(boolean elitist) {
		Set<Edge> tmp = this.environment.getEdges(this, elitist);
		return tmp;
	}
	
	@SuppressWarnings("unchecked")
	public Set<Agent> getNeighbours(Agent askingOne) {
		HashSet<Agent> tmp = (HashSet<Agent>) this.agents.clone();
//		System.out.println();
		tmp.remove(askingOne);
		return tmp;
	}

	public boolean isElitist() {
		return this.elitist;
	}
	
	public void giveResources(int resourceId, int resourceAmount) {
		this.resources[resourceId] += resourceAmount;
	}


	public EvolutionaryEnvironment getEnvironment() {
		return this.environment;
	}

	public void makeNewAgents() {
//		while(this.resources[0]
		
	}
}
